package com.yesjava.springbootjpa.demo.service;

import com.yesjava.springbootjpa.demo.entity.Category;
import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;

import java.util.Arrays;
import java.util.List;

import static org.junit.jupiter.api.Assertions.*;
@SpringBootTest
class CategoryServiceTest11 {
    @Autowired
    CategoryService categoryService;

    @Test
    void saveOrUpdateCategory() {
        Category c1 = new Category().setName("计算机");
        Category c11 = new Category().setName("基础理论").setParent(c1);
        Category c11a = new Category().setName("操作系统").setParent(c11);

        Category c12 = new Category().setName("编程语言").setParent(c1);
        Category c12a = new Category().setName("JAVA 语言").setParent(c12);
        Category c12b = new Category().setName("Python 编程").setParent(c12);

        Category c2 = new Category().setName("文学");

        c1.setChildren(Arrays.asList(new Category[]{ c11,c12 }));
        c11.setChildren(Arrays.asList(new Category[]{ c11a }));
        c12.setChildren(Arrays.asList(new Category[]{ c12a,c12b }));
        categoryService.saveOrUpdateCategory(c1);
        categoryService.saveOrUpdateCategory(c2);
        categoryService.saveOrUpdateCategory(c11);
        categoryService.saveOrUpdateCategory(c11a);
        categoryService.saveOrUpdateCategory(c12);
        categoryService.saveOrUpdateCategory(c12a);
        categoryService.saveOrUpdateCategory(c12b);
        System.out.println("哈哈");

    }

    @Test
    void findAll() {
        List<Category> all = categoryService.findAll();
        for (Category category : all) {
            System.out.println(category.getName());
        }

    }

    @Test
    void findTop() {
        List<Category> all = categoryService.findAllTop();
        for (Category category : all) {
            System.out.println(category.getName());
        }

    }

    @Test
    void findById() {
    }

    @Test
    void deleteCategory() {
    }

    @Test
    void deleteCategoryById() {
    }

    @Test
    void deleteBacth() {
    }

    @Test
    void findCategoryAndChildredById() {
    }
}